<?php
namespace App\Service;

use Symfony\Component\
{
    Filesystem\Filesystem,
    Filesystem\Exception\IOExceptionInterface,
    Finder\Finder,
    Yaml\Yaml
};

use SplFileInfo;

class TaxonomiesManager
{
    //use ContainerAwareTrait;

    /**@ string Path to the the */
    private $dbPath;

    public function __construct(string $dbPath) 
    {
        $this->dbPath = $dbPath;
        $filesystem = new Filesystem();
        if (!$filesystem->exists($this->dbPath)) {
            $filesystem->mkdir($this->dbPath);
        }
    }

    public function getTaxonomies() 
    {
        $taxonomies = [];
        $finder = new Finder();
        /**@var SplFileInfo $file */
        foreach ($finder->in($this->dbPath) as $file) {
            $taxonomies[$file->getBaseName(".{$file->getExtension()}")] = Yaml::parseFile($file);
        }
        return $taxonomies;
    }
}